package com.mtiiot.fstcpserver;

import com.mtiiot.fstcpserver.utils.Constants;
import com.mtiiot.fstcpserver.mq.kafka.util.KafkaProperties;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.FileInputStream;
import java.util.Properties;

/**
 * Created by Administrator on 16-5-26.
 */
public class BootStrap {
    private static final Logger logger = LogManager.getLogger(BootStrap.class);
    public static void main(String[] args) {
        try {
            if(args==null||args.length<1){
                System.out.println("参数错误,程序强制终止!");
                return;
            }
            String configPath=args[0];

            Properties pps = new Properties();
            pps.load(new FileInputStream(configPath));
            String logPath=pps.getProperty("fs.logConfigPath");
            String aplicationPath=pps.getProperty("fs.aplicationPath");
            Constants.SYS_ID_FS=pps.getProperty("fs.sys.id");
            // 加载kafka 的配置文件
            String kafkaPath = pps.getProperty("fs.kafka.properties");
            KafkaProperties.properties = KafkaProperties.loadProperties(kafkaPath);


            System.setProperty("configPath","file:"+args[0]);
//          System.setProperty("log4jPath",args[0]);
//          System.setProperty("configPath",args[1]);
//          System.setProperty("springPath",args[2]);
//          System.setProperty("log4jPath","E:/workspace_idea/mtiiot/FSTcpServer/log4j.properties");
//          System.setProperty("configPath","E:/workspace_idea/mtiiot/FSTcpServer/config.properties");
//          System.setProperty("springPath","E:/workspace_idea/mtiiot/FSTcpServer/applicationContext-dubbo.xml");
            PropertyConfigurator.configure(logPath);
            //ClassPathXmlApplicationContext context =  new ClassPathXmlApplicationContext("classpath:/applicationContext-dubbo.xml");
           // ClassPathXmlApplicationContext context =  new ClassPathXmlApplicationContext(System.getProperty("springPath"));
           // ApplicationContext context=new FileSystemXmlApplicationContext(aplicationPath);
            ClassPathXmlApplicationContext context =  new ClassPathXmlApplicationContext("file:"+aplicationPath);
            //context.start();
            while(true){
                Thread.sleep(999999999);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
